From 9095bd257b8cd7881cff22537d1e16d2a844b70e Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Thu, 1 Jun 2006 13:42:14 +0000 Subject: [PATCH] Add an icon-spacing style property for the same purpose. 2006-06-01 Matthias Clasen * gtk/gtktoolbutton.c (gtk_tool_button_class_init): Add an icon-spacing style property for the same purpose. * gtk/gtkbutton.c (gtk_button_class_init): Add an image-spacing style property that allows to adjust the spacing between image and label in button. (#320431, James Moger) --- ChangeLog | 7 +++++++ ChangeLog.pre-2-10 | 7 +++++++ gtk/gtkbutton.c | 47 +++++++++++++++++++++++++++++++++++++++------ gtk/gtktoolbutton.c | 39 +++++++++++++++++++++++++++++++++++-- 4 files changed, 92 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9e7278d16b..70b2e0515c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,12 @@ 2006-06-01 Matthias Clasen + * gtk/gtktoolbutton.c (gtk_tool_button_class_init): Add + an icon-spacing style property for the same purpose. + + * gtk/gtkbutton.c (gtk_button_class_init): Add an image-spacing + style property that allows to adjust the spacing between image + and label in button. (#320431, James Moger) + * gtk-pristine/gtkprintoperation-private.h: * gtk-pristine/gtkprintoperation.c: * gtk-pristine/gtkprintoperation-unix.c: Move the diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 9e7278d16b..70b2e0515c 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,5 +1,12 @@ 2006-06-01 Matthias Clasen + * gtk/gtktoolbutton.c (gtk_tool_button_class_init): Add + an icon-spacing style property for the same purpose. + + * gtk/gtkbutton.c (gtk_button_class_init): Add an image-spacing + style property that allows to adjust the spacing between image + and label in button. (#320431, James Moger) + * gtk-pristine/gtkprintoperation-private.h: * gtk-pristine/gtkprintoperation.c: * gtk-pristine/gtkprintoperation-unix.c: Move the diff --git a/gtk/gtkbutton.c b/gtk/gtkbutton.c index f21b7e15ed..980dd31bc3 100644 --- a/gtk/gtkbutton.c +++ b/gtk/gtkbutton.c @@ -102,6 +102,8 @@ static void gtk_button_realize (GtkWidget *widget); static void gtk_button_unrealize (GtkWidget *widget); static void gtk_button_map (GtkWidget *widget); static void gtk_button_unmap (GtkWidget *widget); +static void gtk_button_style_set (GtkWidget *widget, + GtkStyle *prev_style); static void gtk_button_size_request (GtkWidget *widget, GtkRequisition *requisition); static void gtk_button_size_allocate (GtkWidget *widget, @@ -168,6 +170,7 @@ gtk_button_class_init (GtkButtonClass *klass) widget_class->unrealize = gtk_button_unrealize; widget_class->map = gtk_button_map; widget_class->unmap = gtk_button_unmap; + widget_class->style_set = gtk_button_style_set; widget_class->size_request = gtk_button_size_request; widget_class->size_allocate = gtk_button_size_allocate; widget_class->expose_event = gtk_button_expose; @@ -287,14 +290,14 @@ gtk_button_class_init (GtkButtonClass *klass) /** * GtkButton:image-position: * - * Sets the position of the image relative to the text inside the button. + * The position of the image relative to the text inside the button. * * Since: 2.10 */ g_object_class_install_property (gobject_class, PROP_IMAGE_POSITION, g_param_spec_enum ("image-position", - P_("Image position"), + P_("Image position"), P_("The position of the image relative to the text"), GTK_TYPE_POSITION_TYPE, GTK_POS_LEFT, @@ -461,6 +464,23 @@ gtk_button_class_init (GtkButtonClass *klass) GTK_TYPE_BORDER, GTK_PARAM_READABLE)); + /** + * GtkButton::image-spacing: + * + * Spacing in pixels between the image and label. + * + * Since: 2.10 + */ + gtk_widget_class_install_style_property (widget_class, + g_param_spec_int ("image-spacing", + P_("Image spacing"), + P_("Spacing in pixels between the image and label"), + 0, + G_MAXINT, + 2, + GTK_PARAM_READABLE)); + + gtk_settings_install_property (g_param_spec_boolean ("gtk-button-images", P_("Show button images"), P_("Whether stock icons should be shown in buttons"), @@ -696,6 +716,7 @@ gtk_button_construct_child (GtkButton *button) GtkWidget *align; GtkWidget *image = NULL; gchar *label_text = NULL; + gint image_spacing; if (!button->constructed) return; @@ -703,6 +724,10 @@ gtk_button_construct_child (GtkButton *button) if (!button->label_text && !priv->image) return; + gtk_widget_style_get (GTK_WIDGET (button), + "image-spacing", &image_spacing, + NULL); + if (priv->image && !priv->image_is_stock) { image = g_object_ref (priv->image); @@ -738,9 +763,9 @@ gtk_button_construct_child (GtkButton *button) if (priv->image_position == GTK_POS_LEFT || priv->image_position == GTK_POS_RIGHT) - box = gtk_hbox_new (FALSE, 2); + box = gtk_hbox_new (FALSE, image_spacing); else - box = gtk_vbox_new (FALSE, 2); + box = gtk_vbox_new (FALSE, image_spacing); if (priv->align_set) align = gtk_alignment_new (priv->xalign, priv->yalign, 0.0, 0.0); @@ -979,6 +1004,13 @@ gtk_button_unmap (GtkWidget *widget) GTK_WIDGET_CLASS (gtk_button_parent_class)->unmap (widget); } +static void +gtk_button_style_set (GtkWidget *widget, + GtkStyle *prev_style) +{ + gtk_button_construct_child (GTK_BUTTON (widget)); +} + static void gtk_button_get_props (GtkButton *button, GtkBorder *default_border, @@ -1943,7 +1975,8 @@ gtk_button_get_image (GtkButton *button) * @button: a #GtkButton * @position: the position * - * Sets the position of the image relative to the text inside the button. + * Sets the position of the image relative to the text + * inside the button. * * Since: 2.10 */ @@ -1973,7 +2006,8 @@ gtk_button_set_image_position (GtkButton *button, * gtk_button_get_image_position: * @button: a #GtkButton * - * Gets the position of the image relative to the text inside the button. + * Gets the position of the image relative to the text + * inside the button. * * Return value: the position * @@ -1991,5 +2025,6 @@ gtk_button_get_image_position (GtkButton *button) return priv->image_position; } + #define __GTK_BUTTON_C__ #include "gtkaliasdef.c" diff --git a/gtk/gtktoolbutton.c b/gtk/gtktoolbutton.c index ee1183fdd3..f52e23aac3 100644 --- a/gtk/gtktoolbutton.c +++ b/gtk/gtktoolbutton.c @@ -74,6 +74,8 @@ static void gtk_tool_button_toolbar_reconfigured (GtkToolItem *tool_item); static gboolean gtk_tool_button_create_menu_proxy (GtkToolItem *item); static void button_clicked (GtkWidget *widget, GtkToolButton *button); +static void gtk_tool_button_style_set (GtkWidget *widget, + GtkStyle *prev_style); static void gtk_tool_button_construct_contents (GtkToolItem *tool_item); @@ -115,11 +117,13 @@ static void gtk_tool_button_class_init (GtkToolButtonClass *klass) { GObjectClass *object_class; + GtkWidgetClass *widget_class; GtkToolItemClass *tool_item_class; parent_class = g_type_class_peek_parent (klass); object_class = (GObjectClass *)klass; + widget_class = (GtkWidgetClass *)klass; tool_item_class = (GtkToolItemClass *)klass; object_class->set_property = gtk_tool_button_set_property; @@ -127,6 +131,8 @@ gtk_tool_button_class_init (GtkToolButtonClass *klass) object_class->notify = gtk_tool_button_property_notify; object_class->finalize = gtk_tool_button_finalize; + widget_class->style_set = gtk_tool_button_style_set; + tool_item_class->create_menu_proxy = gtk_tool_button_create_menu_proxy; tool_item_class->toolbar_reconfigured = gtk_tool_button_toolbar_reconfigured; @@ -221,6 +227,22 @@ gtk_tool_button_class_init (GtkToolButtonClass *klass) GTK_TYPE_WIDGET, GTK_PARAM_READWRITE)); + /** + * GtkButton::icon-spacing: + * + * Spacing in pixels between the icon and label. + * + * Since: 2.10 + */ + gtk_widget_class_install_style_property (widget_class, + g_param_spec_int ("icon-spacing", + P_("Icon spacing"), + P_("Spacing in pixels between the icon and label"), + 0, + G_MAXINT, + 0, + GTK_PARAM_READWRITE)); + /** * GtkToolButton::clicked: * @toolbutton: the object that emitted the signal @@ -271,6 +293,11 @@ gtk_tool_button_construct_contents (GtkToolItem *tool_item) gboolean need_icon = FALSE; GtkIconSize icon_size; GtkWidget *box = NULL; + guint icon_spacing; + + gtk_widget_style_get (GTK_WIDGET (tool_item), + "icon-spacing", &icon_spacing, + NULL); if (button->priv->icon_widget && button->priv->icon_widget->parent) { @@ -398,7 +425,7 @@ gtk_tool_button_construct_contents (GtkToolItem *tool_item) break; case GTK_TOOLBAR_BOTH: - box = gtk_vbox_new (FALSE, 0); + box = gtk_vbox_new (FALSE, icon_spacing); if (icon) gtk_box_pack_start (GTK_BOX (box), icon, TRUE, TRUE, 0); gtk_box_pack_start (GTK_BOX (box), label, FALSE, TRUE, 0); @@ -406,7 +433,7 @@ gtk_tool_button_construct_contents (GtkToolItem *tool_item) break; case GTK_TOOLBAR_BOTH_HORIZ: - box = gtk_hbox_new (FALSE, 0); + box = gtk_hbox_new (FALSE, icon_spacing); if (icon) gtk_box_pack_start (GTK_BOX (box), icon, label? FALSE : TRUE, TRUE, 0); if (label) @@ -638,6 +665,13 @@ gtk_tool_button_toolbar_reconfigured (GtkToolItem *tool_item) gtk_tool_button_construct_contents (tool_item); } +static void +gtk_tool_button_style_set (GtkWidget *widget, + GtkStyle *prev_style) +{ + gtk_tool_button_construct_contents (GTK_TOOL_ITEM (widget)); +} + /** * gtk_tool_button_new_from_stock: * @stock_id: the name of the stock item @@ -1037,5 +1071,6 @@ _gtk_tool_button_get_button (GtkToolButton *button) return button->priv->button; } + #define __GTK_TOOL_BUTTON_C__ #include "gtkaliasdef.c" -- 2.30.2